package com.neuedu.funlifebbs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neuedu.funlifebbs.bean.Topics;
import com.neuedu.funlifebbs.dao.TopicsMapper;
import com.neuedu.funlifebbs.query.TopicsQuery;
import com.neuedu.funlifebbs.service.TopicsServic;

/**
 * @author jds
 *
 * @version 2019年8月19日 上午9:52:12
 */
@Service
public class TopicsServiceImpl implements TopicsServic {

	@Autowired
	TopicsMapper topicsMapper;

	@Override
	public int add(Topics topics) {

		return topicsMapper.add(topics);
	}

	@Override
	public int deleteById(int id) {
		return topicsMapper.deleteById(id);
	}

	@Override
	public int update(Topics topics) {
		return topicsMapper.update(topics);
	}

	@Override
	public PageInfo<Topics> query(TopicsQuery topicsQuery) {

		if (topicsQuery.isPaging()) {
			// 使用分页插件
			Page<Topics> pageInfo = PageHelper.startPage(
					topicsQuery.getPageNum(), topicsQuery.getLimit());
			topicsMapper.query(topicsQuery);
			return pageInfo.toPageInfo();
		} else {

			PageInfo<Topics> pageInfo = new PageInfo<Topics>(
					topicsMapper.query(topicsQuery));
			return pageInfo;
		}
	}

	@Override
	public List<Topics> findAll() {
		return topicsMapper.findAll();
	}

	@Override
	public Topics findById(int id) {
		return topicsMapper.findById(id);
	}

	@Override
	public List<Topics> findByCategorysId(int id) {
		return topicsMapper.findByCategorysId(id);
	}

}
